﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy_oppssum : Enemy
{
    private Rigidbody2D rb;
    private Collider2D coll;
    public float speed;

    private Transform Boundaries, left, right;
    private float leftPoint, rightPoint;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        coll = GetComponent<Collider2D>();
        base.Start();

        Boundaries = transform.GetChild(0);
        left = Boundaries.GetChild(0);
        right = Boundaries.GetChild(1);

        transform.DetachChildren();
        leftPoint = left.position.x;
        rightPoint = right.position.x;
        Destroy(Boundaries.gameObject);
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        Movement();
    }

    void Movement()
    {
        rb.velocity = new Vector2(-transform.localScale.x * speed * Time.deltaTime, rb.velocity.y);
        if (transform.position.x < leftPoint || transform.position.x > rightPoint)
        {
            rb.velocity = new Vector2(rb.velocity.x * -1, rb.velocity.y);
            transform.localScale = new Vector3(transform.localScale.x * -1, 1, 1);
        }
    }
}
